package eight.test_8_1;

import java.util.Scanner;

public class TestMain2 {
    public static int min = Integer.MAX_VALUE;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int v = scanner.nextInt();
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        for (int i = 0; i < n; i++) {
            dfs(arr,v,arr[i],i);
        }
        System.out.println(min);
    }
    public static void dfs(int[] arr,int v,int count,int i) {
        if(count > v) {
            return;
        }
        boolean b = true;
        int tmp = arr[i];
        arr[i] = -1;
        for (int j = 0; j < arr.length; j++) {
            if(arr[j] != -1) {
                dfs(arr,v,count + arr[j],j);
                b = false;
            }
        }
        arr[i] = tmp;
        min = Math.min(min,v - count);
        if (b) {
            return;
        }
    }
}
